package com.ask.controller;

import com.ask.dto.Result;
import com.ask.threadlocals.StringHolder;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/tl")
public class ThreadLocalController {

    @PostMapping
    public Result setString(String string) {
        StringHolder.setString(string);
        return Result.success("set string :" + string);
    }

    @GetMapping
    public String getString() {
        String string = StringHolder.getString();
        return string == null ? "get null" : string;
    }
}
